/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admin.recordatorio;

import DBMS.DataBaseManager;
import clases.Recordatorio;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author andreth
 */
public class VerCalendario extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";
    private final static String FAILURE = "failure";
    private static final String name = "Ver Calendario";

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        //Necesario al pulsar en calendario en el top menu
        Recordatorio recordatorio = (Recordatorio) form;
        DataBaseManager dbm = DataBaseManager.getInstance();
        ArrayList<String> fechas = DataBaseManager.getFechas();
        System.out.println("Tamano de fechas"+ fechas.size());
        request.setAttribute("anos", fechas);
        ArrayList<Recordatorio> resultadoConsulta =
                dbm.consultarRecordatorios(recordatorio);

        if (resultadoConsulta == null || resultadoConsulta.isEmpty()) {
            //recordatorio.setMensaje("No se ha podido extraer los recordatorios.");
            request.setAttribute("recordatorio", recordatorio);
            return mapping.findForward(FAILURE);
        }

        request.setAttribute("recordatorio", resultadoConsulta);
        return mapping.findForward(SUCCESS);
    }
}
